import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class webStatsSystem{
    private List<webPage> pages=new ArrayList<>();
    public void recordVisit(String url){
        for(webPage page:pages){
            if(page.getUrl().equals(url)){
                page.visitPage();
                return;
            }
        }
        webPage newPage=new webPage(url);
        newPage.visitPage();
        pages.add(newPage);
    }
    public void visitPageRank(){
        pages.sort((p1,p2)->p2.getVisitCount().compareTo(p1.getVisitCount()));
        for(webPage page:pages){
            System.out.println("URL:"+page.getUrl()+"访问量:"+page.getVisitCount());
        }
    }
    public int getTotalVisitCount(){
        int totalVisitCount=0;
        for(webPage page:pages){
            totalVisitCount+=page.getVisitCount();
        }
        return totalVisitCount;
    }
    public double getAverageVisitCount(){
        if (pages.isEmpty())return 0;
        float totalVisitCount=getTotalVisitCount();
        return totalVisitCount/pages.size();
    }
    public Date getLastVisitDate(String url){
        for(webPage page:pages){
            if(page.getUrl().equals(url)){
                return page.getLastVisitTime();
            }
        }
        return null;
    }
    public void clearStats(){
        for(webPage page:pages){
            page.resetVisitCount();
        }
    }
}